using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace FAS.Utilities
{
    public class Utils
    {
        public static bool CheckDataBase(DataSet ds, int indexTable)
        {
            if (ds != null
                && ds.Tables != null
                && ds.Tables.Count > indexTable
                && ds.Tables[indexTable].Rows != null
                && ds.Tables[indexTable].Rows.Count > 0)
            {
                return true;
            }

            return false;
        }

        public static bool CheckDataBase(DataTable dt)
        {
            if (dt != null
                && dt.Rows != null
                && dt.Rows.Count > 0)
            {
                return true;
            }

            return false;
        }

        public static String ConvertToHHmmssAmPm(Object obj)
        {
            if (obj != null && !"".Equals(obj.ToString()))
            {
                return String.Format("{0:T}", Convert.ToDateTime(obj));
            }
            return String.Empty;
        }

        public static DateTime ConvertToDateTime(Object obj)
        {
            if (obj != null && !"".Equals(obj.ToString()))
            {
                DateTime dt = Convert.ToDateTime(obj);
                return dt;
            }

            return Convert.ToDateTime("1900-01-01");
        }

        public static bool ConvertToBool(object obj)
        {
            if (obj == null || DBNull.Value.Equals(obj))
            {
                return false;
            }

            try
            {
                return Convert.ToBoolean(obj);
            }
            catch { }

            return false;
        }

        public static double ConvertToDouble(object obj)
        {
            if (obj == null || DBNull.Value.Equals(obj))
            {
                return 0;
            }

            try
            {
                return Convert.ToDouble(obj);
            }
            catch { }

            return 0;
        }

        public static int ConvertToInt(object obj)
        {
            if (obj == null || DBNull.Value.Equals(obj))
            {
                return 0;
            }

            try
            {
                return Convert.ToInt32(obj);
            }
            catch { }

            return 0;
        }
    }
}
